<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:dcterms="http://purl.org/dc/terms/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:skos="http://www.w3.org/2004/02/skos/core#">
<!-- Developed by Christophe Dupriez for the ASKOSI project
     http://www.askosi.org
     Please feel free to modify but please keep this reference -->	 
    <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
    
    <xsl:template match="/">
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
				<title><xsl:value-of select="rdf:RDF/skos:ConceptScheme/dc:title[@xml:lang='en']"/></title>
            </head>
            <body>
                <style type="text/css">
body { font-size:10pt;
       font-style: normal;
	   font-family: Verdana;
	 }

a {
  	text-decoration: none;
}
	 
table.ABOUT {
	border:  1px solid #8A8;
    margin:  2px;
    padding: 2px;
    margin-bottom: 10px;
    background-color: #EEF
}

.FIELD-HEADERS {
}

.FIELD-VALUE {
    font-weight: bold;
    background-color: #EEF
}

.CONCEPT-FIELD {
    background-color: #FEE;
	white-space:nowrap;
}

.SN {
    background-color: #EEF
}

.PREF {
    font-weight: bold;
}

.URI {
    color: blue;
}

.conceptURI {
    color: brown;
}

.STATUS {
    color: darkgreen;
}

.ALT {
}

.HID {
   color:grey
}
                </style>
                
                <xsl:call-template name="schemeAbout" />
                <xsl:call-template name="topConcept" />
                <xsl:call-template name="termList" />
                
            </body>
        </html>
    </xsl:template>
    
    <xsl:template name="schemeAbout">
       <h1><a name="top"/><xsl:value-of select="rdf:RDF/skos:ConceptScheme/dc:title[@xml:lang='en']"/></h1>
        <table class="ABOUT">
            <tbody>
                <xsl:for-each select="rdf:RDF/skos:ConceptScheme/*[namespace-uri()='http://purl.org/dc/elements/1.1/']">
                    <tr>
                        <td class="FIELD-HEADERS"><xsl:value-of select="local-name()"/>-<xsl:value-of select="@xml:lang"/>:</td>
                        <td class="FIELD-VALUE"><xsl:if test="@xml:lang='ar'"><xsl:attribute name="dir">RTL</xsl:attribute></xsl:if><xsl:value-of select="."/></td>
                    </tr>
                </xsl:for-each>
                <xsl:for-each select="rdf:RDF/skos:ConceptScheme/*[namespace-uri()='http://purl.org/dc/terms/']">
                    <tr>
                        <td class="FIELD-HEADERS"><xsl:value-of select="local-name()"/>-<xsl:value-of select="@xml:lang"/>:</td>
                        <td class="FIELD-VALUE"><xsl:if test="@xml:lang='ar'"><xsl:attribute name="dir">RTL</xsl:attribute></xsl:if><xsl:value-of select="."/></td>
                        
                    </tr>
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>

    <xsl:template name="topConcept">
        <ul>
            <xsl:for-each select="rdf:RDF/skos:ConceptScheme/skos:hasTopConcept/@rdf:resource">
                <xsl:variable name="topConceptURI" select="."/>
                <xsl:variable name="topConceptLabel" select="/rdf:RDF/skos:Concept/skos:prefLabel[./../@rdf:about=$topConceptURI][@xml:lang='']"/>
                <xsl:variable name="topConceptLabelEN" select="/rdf:RDF/skos:Concept/skos:prefLabel[./../@rdf:about=$topConceptURI][@xml:lang='en']"/>
                <xsl:variable name="topConceptLabelLA" select="/rdf:RDF/skos:Concept/skos:prefLabel[./../@rdf:about=$topConceptURI][@xml:lang='la']"/>
                
                <li class="TERM-TOP"><a><xsl:attribute name="href">#<xsl:value-of select="$topConceptURI"/></xsl:attribute><xsl:value-of select="$topConceptLabelLA"/> -- <xsl:value-of select="$topConceptLabelEN"/> -- <xsl:value-of select="$topConceptLabel"/></a>
                    <xsl:call-template name="narrowerTerm">
                        <xsl:with-param name="broaderTermURI" select="." />
                    </xsl:call-template>
                </li>
            </xsl:for-each>
        </ul>
    </xsl:template>
    
    <xsl:template name="narrowerTerm">
        <xsl:param name="broaderTermURI"/>
        <ul>
            <xsl:for-each select="/rdf:RDF/skos:Concept[skos:broader/@rdf:resource=$broaderTermURI]">
                <li><a><xsl:attribute name="href">#<xsl:value-of select="./@rdf:about"/></xsl:attribute><xsl:value-of select="./skos:prefLabel[@xml:lang='la']" />  -- <xsl:value-of select="./skos:prefLabel[@xml:lang='en']"/> -- <xsl:value-of select="./skos:prefLabel[@xml:lang='']"/></a></li>
                <xsl:call-template name="narrowerTerm">
                    <xsl:with-param name="broaderTermURI" select="@rdf:about" />
                </xsl:call-template>
            </xsl:for-each>
        </ul>
    </xsl:template>
    
    <xsl:template name="termList">
        <xsl:for-each select="/rdf:RDF/skos:Concept">
            <a><xsl:attribute name="name"><xsl:value-of select="@rdf:about"/></xsl:attribute></a>
            <h2><a href="#top">&#8657;</a> <xsl:value-of select="./skos:prefLabel[@xml:lang='la']"/> -- <xsl:value-of select="./skos:prefLabel[@xml:lang='en']"/> -- <xsl:value-of select="./skos:prefLabel[@xml:lang='']"/></h2>
            <table class="TERM">
                <tbody>    
                    <tr><td class="CONCEPT-FIELD">URI</td><td class="conceptURI"><a><xsl:attribute name="href"><xsl:value-of select="@rdf:about"/></xsl:attribute><xsl:value-of select="@rdf:about"/></a></td></tr>
                    <xsl:for-each select="./skos:prefLabel">
						<tr><td class="CONCEPT-FIELD">Preferred label (<xsl:value-of select="@xml:lang"/>)</td><td class="PREF"><xsl:if test="@xml:lang='ar'"><xsl:attribute name="dir">RTL</xsl:attribute></xsl:if><xsl:value-of select="."/> <a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:altLabel">
						<tr><td class="CONCEPT-FIELD">Alternative label (<xsl:value-of select="@xml:lang"/>)</td><td class="ALT"><xsl:if test="@xml:lang='ar'"><xsl:attribute name="dir">RTL</xsl:attribute></xsl:if><xsl:value-of select="."/> <a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:hiddenLabel">
						<tr><td class="CONCEPT-FIELD">Hidden label (<xsl:value-of select="@xml:lang"/>)</td><td class="HID"><xsl:if test="@xml:lang='ar'"><xsl:attribute name="dir">RTL</xsl:attribute></xsl:if><xsl:value-of select="."/> <a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:exactMatch">
						<tr><td class="CONCEPT-FIELD">Exact match</td><td class="URI"><a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:closeMatch">
						<tr><td class="CONCEPT-FIELD">Close match</td><td class="URI"><a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:broader">
						<tr><td class="CONCEPT-FIELD">Broader</td><td class="URI"><a><xsl:attribute name="href">#<xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:narrower">
						<tr><td class="CONCEPT-FIELD">Narrower</td><td class="URI"><a><xsl:attribute name="href">#<xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:related">
						<tr><td class="CONCEPT-FIELD">Related</td><td class="URI"><a><xsl:attribute name="href">#<xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:relatedMatch">
						<tr><td class="CONCEPT-FIELD">Related match</td><td class="URI"><a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:changeNote">
                        <tr><td class="CONCEPT-FIELD">Change note (<xsl:value-of select="@xml:lang"/>)</td><td class="SN"><xsl:value-of select="."/> <a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:definition">
                        <tr><td class="CONCEPT-FIELD">Definition (<xsl:value-of select="@xml:lang"/>)</td><td class="SN"><xsl:value-of select="."/> <a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:editorialNote">
                        <tr><td class="CONCEPT-FIELD">Editorial note (<xsl:value-of select="@xml:lang"/>)</td><td class="SN"><xsl:value-of select="."/> <a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:example">
                        <tr><td class="CONCEPT-FIELD">Example (<xsl:value-of select="@xml:lang"/>)</td><td class="SN"><xsl:value-of select="."/> <a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:historyNote">
                        <tr><td class="CONCEPT-FIELD">History note (<xsl:value-of select="@xml:lang"/>)</td><td class="SN"><xsl:value-of select="."/> <a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <xsl:for-each select="./skos:scopeNote">
                        <tr><td class="CONCEPT-FIELD">Scope note (<xsl:value-of select="@xml:lang"/>)</td><td class="SN"><xsl:value-of select="."/> <a><xsl:attribute name="href"><xsl:value-of select="@rdf:resource"/></xsl:attribute><xsl:value-of select="@rdf:resource"/></a></td></tr>
                    </xsl:for-each>
                    <!--tr><td class="CONCEPT-FIELD">Status</td><td class="STATUS"><xsl:value-of select="./skos:status/@rdf:resource"/></td></tr-->
                    <tr><td class="CONCEPT-FIELD">Scheme</td><td class="URI"><a><xsl:attribute name="href"><xsl:value-of select="./skos:inScheme/@rdf:resource"/></xsl:attribute><xsl:value-of select="./skos:inScheme/@rdf:resource"/></a></td></tr>
                </tbody></table>    
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
